<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<title>用户支付</title>
<script src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>
<link type="text/css" rel="stylesheet" href="${basePath}resources/css/pay.css">
<script type="text/javascript" src="${basePath}resources/js/fontset.js"></script>
</head>
<body>
	<header class="header">
		<div class="pay_toudaohang">
			<span><img src="${basePath}resources/images/shiliangtu/33.png"> </span> <span>用户支付</span>
		</div>
	</header>
	<div class="body">
		<div class="pay_bddv1">
			<img src="${basePath}resources/images/web/logo.png" alt="">
			<p>游艺设备 智能物联</p>
		</div>
		<div class="pay_bddv2">
			<p>
				<span>设备情况</span> <span id="pay_bdonline"   ${status eq "true"?"":"class=\"cur\""} >${status eq "true"?"在线":"离线"}</span>
			</p>
			<ul>
				<c:forEach var="entry" items="${discounts}" varStatus="index">
					<li>${entry.money}元${entry.coin}币</li>
					<input type="hidden" value="${entry.discountid }"
						id="discountid${index.index}" />
				</c:forEach>
			</ul>
		</div>
	</div>

	<form id="alipaysubmit" name="alipaysubmit"
		action="https://mapi.alipay.com/gateway.do?_input_charset=utf-8"
		method="get">
		<input type="hidden" name="_input_charset" value="" />
		<input type="hidden" name="subject" value="" />
		<input type="hidden" name="sign" value="" />
		<input type="hidden" name="notify_url" value="" />
		<input type="hidden"name="body" value="" />
		<input type="hidden" name="payment_type" value=1" />
		<input type="hidden" name="out_trade_no" value="" />
		<input type="hidden" name="partner" value="" />
		<input type="hidden" name="service" value="" />
		<input type="hidden" name="total_fee" value="" />
		<input type="hidden" name="return_url" value="" />
		<input type="hidden" name="sign_type" value="" />
		<input type="hidden" name="seller_id" value="" />
	</form>


</body>
</html>
<script type="text/javascript">
	$(function() {
		$(
				".pay_bdtanchuang, .pay_bdoffline, .pay_bdpaypassword, .pay_bdkeyboard")
				.hide();
		var pay_bdonline = $("#pay_bdonline").text();
		$(".pay_bddv2 ul li").each(function(n) {
			$(this).click(function() {
				prepay($("#discountid"+n).val());

			});

		});

	});

	function prepay(discountid){
		if(!${status}){
			alert('设备离线，无法支付');
			return ;
		}
		$.ajax({
			url: '${basePath}/payinfo/prePayInAlipay',			
			type: "POST",
			data: {
				deviceid:'${deviceId}',
				openid:'${openid}',
				discountid:discountid
			},
			dataType: "json",
			cache: false,	
			success: function(message) {
				
				if (message.message.type == "success") {
					$("input[name='_input_charset']").val(message.orderinfo._input_charset);
					$("input[name='subject']").val(message.orderinfo.subject);
					$("input[name='sign']").val(message.orderinfo.sign);
					$("input[name='notify_url']").val(message.orderinfo.notify_url);
					$("input[name='body']").val(message.orderinfo.body);
					$("input[name='payment_type']").val(message.orderinfo.payment_type);
					$("input[name='out_trade_no']").val(message.orderinfo.out_trade_no);
					$("input[name='partner']").val(message.orderinfo.partner);
					$("input[name='service']").val(message.orderinfo.service);
					$("input[name='total_fee']").val(message.orderinfo.total_fee);
					$("input[name='return_url']").val(message.orderinfo.return_url);
					$("input[name='sign_type']").val(message.orderinfo.sign_type);
					$("input[name='seller_id']").val(message.orderinfo.seller_id);
					document.forms['alipaysubmit'].submit();
					
						 
				} else {
					alert(message.message.content);
				}
			
			}
		});
	}
	

</script>
